/**
 * @file tiny_semaphore.h
 * @author LuckKey 
 * @author 张恒宣 
 * @LastEditTime 2024/9/22
 * 
 * MIT License
 *
 * Copyright (c) 2025 张恒宣 luckkeymail@163.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */


#ifndef __TINY_SEMAPHORE_H__
#define __TINY_SEMAPHORE_H__

/*********************
 *       头文件
 *********************/

#include "tiny_def.h"
#include "tiny_list.h"

/**********************
 *      类型定义
 **********************/

struct tiny_semaphore
{
    tiny_int32_t val;
    tiny_int32_t max_val;
    tiny_list_t receiver_list;
};

typedef struct tiny_semaphore *tiny_semaphore_t;

/**********************
 *       函数声明
 **********************/

tiny_semaphore_t tiny_semaphore_create(tiny_int32_t init_val, tiny_int32_t max_val);
tiny_semaphore_t tiny_binary_semaphore_create(void);
void tiny_semaphore_release(tiny_semaphore_t semaphore);
tiny_ret_status_t tiny_semaphore_take(tiny_semaphore_t semaphore, tiny_int32_t timeout);
tiny_ret_status_t tiny_semaphore_give(tiny_semaphore_t semaphore);

#endif //! __TINY_SEMAPHORE_H__
